package com.spatio.serving.basic.service.template.common.util;

import java.time.*;
import java.time.format.DateTimeFormatter;

/**
 * @Description
 * @Author GuoPengfei
 * @Date 2023/12/8 17:05
 */
public class DateUtils {

    private static final DateTimeFormatter DATE_FORMATTER_yyyyMMdd = DateTimeFormatter.ofPattern("yyyyMMdd");
    private static final DateTimeFormatter TIME_FORMATTER_HHmmss = DateTimeFormatter.ofPattern("HH:mm:ss");
    private static final DateTimeFormatter TIME_FORMATTER_yyyyMMdd_HHmms = DateTimeFormatter.ofPattern("yyyyMMdd-HH:mm:ss");


    /**
     *
     * @param zoneId eg:+8
     * @return
     */
    public static LocalDateTime getLocalDate(String zoneId) {
        return ZonedDateTime.now(ZoneId.of(zoneId)).toLocalDateTime();
    }

    public static String getDateFormat(LocalDateTime localDateTime) {
        return localDateTime.format(DATE_FORMATTER_yyyyMMdd);
    }

    public static String getTimeFormat(LocalDateTime localDateTime) {
        return localDateTime.format(TIME_FORMATTER_HHmmss);
    }

    public static String getTimeFormatByTimeAndZone(Long timestamp, String zoneId){
        Instant instant = Instant.ofEpochMilli(timestamp);
        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.of(zoneId));
        return localDateTime.format(TIME_FORMATTER_yyyyMMdd_HHmms);
    }

    public static void main(String[] args) {
        /*
        LocalDateTime currentDateTime = getLocalDate(TIME_ZONE_MAP.get("kr"));
        System.out.println("Formatted Date: " + getDateFormat(currentDateTime));
        System.out.println("Formatted Time: " + getTimeFormat(currentDateTime));
        LocalDateTime t1 = getLocalDate("+12");
        System.out.println(getDateFormat(t1));
        LocalDateTime t2 = getLocalDate("+13");
        System.out.println(getDateFormat(t2));

         */
        Long timestamp = 1705995658000L;
        Instant instant = Instant.ofEpochMilli(timestamp);
        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.of("+8"));
        String str = localDateTime.format(TIME_FORMATTER_yyyyMMdd_HHmms);

    }

}